import request from '@/router/axios';
import {baseUrl} from '@/config/env';
// import website from "@/config/website";

// export const loginByUsername = (tenantId, account, password, type, key, code) => request({
export const loginByUsername = (params) => request({
  // url: '/api/blade-auth/token',
  url: '/api/PcLogin/AccountLogin',
  method: 'post',
  headers: {
    'Captcha-Key': params.key,
    'Captcha-Code': params.code,
  },
  data:params
  // params: {
  //   grantType: (website.captchaMode ? "captcha" : "password"),
  //   tenantId,
  //   account,
  //   password,
  //   type
  // }
});

export const loginBySocial = (tenantId, source, code, state) => request({
  // url: '/api/blade-auth/token',
  url: '/api/PcLogin/AccountLogin',
  method: 'post',
  headers: {
    'Tenant-Id': tenantId
  },
  params: {
    tenantId,
    source,
    code,
    state,
    grantType: "social",
    scope: "all",
  }
});

export const getButtons = () => request({
  // url: '/api/blade-system/menu/buttons',
  url: '/api/ManageMenu/GetMenuButtonByAccount',
  method: 'get'
});


// const api = 'http://8.142.153.155:8024'
const api = 'http://192.168.1.146:8024'
export const getUserInfoNew = (params) => {
  return request({
    url: `${api}/report/getUserInfo`,
    method: 'get',
    params
  })
}

export const getUserInfo = () => request({
  url: baseUrl + '/user/getUserInfo',
  method: 'get'
});

export const refreshToken = () => request({
  url: baseUrl + '/user/refesh',
  method: 'post'
})

export const registerGuest = (form, oauthId) => request({
  url: '/api/blade-user/register-guest',
  method: 'post',
  params: {
    tenantId: form.tenantId,
    name: form.name,
    account: form.account,
    password: form.password,
    oauthId
  }
});

export const getMenu = () => request({
  // url: '/api/blade-system/menu/routes',
  url: '/api/ManageMenu/GetMenuByAccount',
  method: 'get'
});

export const getCaptcha = () => request({
  url: '/api/blade-auth/captcha',
  method: 'get'
});

export const getTopMenu = () => request({
  url: baseUrl + '/user/getTopMenu',
  method: 'get'
});

export const sendLogs = (list) => request({
  url: baseUrl + '/user/logout',
  method: 'post',
  data: list
})

export const logout = () => request({
  url: baseUrl + '/user/logout',
  method: 'get'
})
export const getUserInfoById = (id) => request({
  url:'/api/AppLogin/getUserInfoById',
  method: 'get',
  params:{
    id,
  }
})
